<?php
namespace app\admin\controller\general;
use app\admin\controller\Backend;
/**
 * 系统配置
 *
 * @icon fa fa-circle-o
 */
class Config extends Backend
{

    protected $model = null;
    protected $noNeedRight = ['check'];

    public function _initialize()
    {
        parent::_initialize();
    }

    public function index()
    {
        $row = config('product');
        $this->view->assign('row', $row);
        return $this->view->fetch();
    }

    public function save() {
        if($this->request->isPost()) {
            $row = $this->request->post('row/a');
            $config = array_merge(config('product'), $row);
            $filename = CONF_PATH.'extra/product.php';
            $result = file_put_contents($filename, ("<?php \r\n return " . var_export($config, true) . ";"));
            if($result) {
                return $this->success('操作成功');
            } else {
                return $this->error('配置文件写入失败，请检查权限');
            }

        } else {
            return $this->error('请勿非法访问');
        }
    }

}
